package com.sqfw.project.wp.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sqfw.framework.web.domain.TreeSelect;
import com.sqfw.project.system.domain.SysDept;
import com.sqfw.project.system.service.ISysDeptService;
import com.sqfw.project.wp.domain.SysCode;
import com.sqfw.project.wp.domain.WpTreeSelect;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sqfw.framework.aspectj.lang.annotation.Log;
import com.sqfw.framework.aspectj.lang.enums.BusinessType;
import com.sqfw.project.wp.domain.SysStruBak;
import com.sqfw.project.wp.service.ISysStruBakService;
import com.sqfw.framework.web.controller.BaseController;
import com.sqfw.framework.web.domain.AjaxResult;
import com.sqfw.common.utils.poi.ExcelUtil;
import com.sqfw.framework.web.page.TableDataInfo;

/**
 * 部门字典表Controller
 * 
 * @author lx
 * @date 2023-06-09
 */
@Api(tags = "部门字典树")
@RestController
@RequestMapping("/wp/sys_stru_bak")
public class SysStruBakController extends BaseController
{
    @Autowired
    private ISysStruBakService sysStruBakService;

    @Autowired
    private ISysDeptService deptService;

    /**
     * 查询部门字典表列表
     */
    @PreAuthorize("@ss.hasPermi('wp:sys_stru_bak:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysStruBak sysStruBak)
    {
        startPage();
        List<SysStruBak> list = sysStruBakService.selectSysStruBakList(sysStruBak);
        return getDataTable(list);
    }

    /**
     * 导出部门字典表列表
     */
    @PreAuthorize("@ss.hasPermi('wp:sys_stru_bak:export')")
    @Log(title = "部门字典表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysStruBak sysStruBak)
    {
        List<SysStruBak> list = sysStruBakService.selectSysStruBakList(sysStruBak);
        ExcelUtil<SysStruBak> util = new ExcelUtil<SysStruBak>(SysStruBak.class);
        util.exportExcel(response, list, "部门字典表数据");
    }

    /**
     * 获取部门字典表详细信息
     */
    @PreAuthorize("@ss.hasPermi('wp:sys_stru_bak:query')")
    @GetMapping(value = "/{autoId}")
    public AjaxResult getInfo(@PathVariable("autoId") String autoId)
    {
        return success(sysStruBakService.selectSysStruBakByAutoId(autoId));
    }

    /**
     * 新增部门字典表
     */
    @PreAuthorize("@ss.hasPermi('wp:sys_stru_bak:add')")
    @Log(title = "部门字典表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysStruBak sysStruBak)
    {
        return toAjax(sysStruBakService.insertSysStruBak(sysStruBak));
    }

    /**
     * 修改部门字典表
     */
    @PreAuthorize("@ss.hasPermi('wp:sys_stru_bak:edit')")
    @Log(title = "部门字典表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysStruBak sysStruBak)
    {
        return toAjax(sysStruBakService.updateSysStruBak(sysStruBak));
    }

    /**
     * 删除部门字典表
     */
    @PreAuthorize("@ss.hasPermi('wp:sys_stru_bak:remove')")
    @Log(title = "部门字典表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{autoIds}")
    public AjaxResult remove(@PathVariable String[] autoIds)
    {
        return toAjax(sysStruBakService.deleteSysStruBakByAutoIds(autoIds));
    }


    /**
     * TODO  三级承办单位暂时需要跟数据库数据对应
     * @param dept
     * @return
     */
    @ApiOperation("查询部门字典项")
    @PreAuthorize("@ss.hasPermi('getSysStruBakTree')")
    @GetMapping("/getSysStruBakTree")
    public AjaxResult getSysStruBakTree(SysDept dept){

        List<WpTreeSelect> wpTreeSelects = new ArrayList<>();
        List<WpTreeSelect> selects = deptService.selectSysDeptTreeListRevokeCB(dept);
       /* for (WpTreeSelect select : selects) {
            if (1L==select.getValue()){
                wpTreeSelects.add(select);
            }
        }*/

        return success(selects);
    }
}
